home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Jotto2.so Folder / Jotto ][ ƒ / Wipes, etc. / text scroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-02  |  5.8 KB  |  213 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        text scroll.c
  4.  
  5. Purpose:    This modules handles scrolling text (for the alternate
  6.             about box).
  7.  
  8.  
  9. Jotto ][ -=- a simple word game, revisited
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "text scroll.h"
  30. #include "msg graphics.h"
  31. #include "msg error.h"
  32. #include "msg timing.h"
  33. #include "msg environment.h"
  34.  
  35. #define HEADLINE_BOTTOM    40
  36. #define gScrollSpeed    2
  37.  
  38. short                scrollXPos;
  39. long            gScrollPos;
  40. Handle            gTheText;
  41. unsigned char    iv;
  42. Rect            scrollSource;
  43. Rect            scrollDest;
  44. Rect            wholeSource;
  45. Rect            wholeDest;
  46. Rect            gMainRect;
  47.  
  48. Rect            scrollRect;
  49. Ptr                scrollBits;
  50. CGrafPort        scrollCGrafPort;
  51. CGrafPtr        scrollCGrafPtr;
  52. CTabHandle        scrollCMHandle;
  53. GrafPort        scrollGrafPort;
  54. GrafPtr            scrollGrafPtr;
  55. Boolean            isColorScroll;
  56.  
  57. Boolean ScrollIt(void)
  58. {
  59. //    Rect            source, dest;
  60.     unsigned char    theChar;
  61.     
  62.     StartTiming();
  63.     if (isColorScroll)
  64.     {
  65.         SetPort((GrafPtr)scrollCGrafPtr);
  66.         CopyBits(&(((GrafPtr)scrollCGrafPtr)->portBits),
  67.                     &(((GrafPtr)scrollCGrafPtr)->portBits), &scrollSource, &scrollDest, 0, 0L);
  68.     }
  69.     else
  70.     {
  71.         SetPort(scrollGrafPtr);
  72.         CopyBits(&(scrollGrafPtr->portBits),
  73.                     &(scrollGrafPtr->portBits), &scrollSource, &scrollDest, 0, 0L);
  74.     }
  75.     
  76.     MoveTo(scrollXPos, HEADLINE_BOTTOM-10);
  77.     theChar=(*gTheText)[gScrollPos]^iv;
  78.     TextMode(notSrcCopy);
  79.     TextFont(143);
  80.     TextSize(36);
  81.  
  82.     DrawChar(theChar);
  83.     
  84.     if (isColorScroll)
  85.         CopyBits(&(((GrafPtr)scrollCGrafPtr)->portBits),
  86.                     &(((GrafPtr)WMgrPort)->portBits), &wholeSource, &wholeDest, 0, 0L);
  87.     else
  88.         CopyBits(&(scrollGrafPtr->portBits),
  89.                     &(((GrafPtr)WMgrPort)->portBits), &wholeSource, &wholeDest, 0, 0L);
  90.     
  91.     scrollXPos-=gScrollSpeed;
  92.     if (scrollXPos+CharWidth(theChar)<=509-gScrollSpeed)
  93.     {
  94.         scrollXPos+=CharWidth(theChar);
  95.         gScrollPos++;
  96.         iv^=theChar;
  97.         if (gScrollPos==GetHandleSize(gTheText))
  98.             return FALSE;
  99.     }
  100.     SetPort(WMgrPort);
  101.     TimeCorrection(2);
  102.     return TRUE;
  103. }
  104.  
  105. void InitScroll(void)
  106. {
  107.     long        offRowBytes, sizeOfOff;
  108.     short            theDepth, j, err;
  109.     
  110.     gMainRect.top=WMgrPort->portRect.top+
  111.         ((WMgrPort->portRect.bottom-WMgrPort->portRect.top)-342)/2;
  112.     gMainRect.bottom=gMainRect.top+341;
  113.     gMainRect.left=WMgrPort->portRect.left+
  114.         ((WMgrPort->portRect.right-WMgrPort->portRect.left)-512)/2;
  115.     gMainRect.right=gMainRect.left+511;
  116.     gScrollPos=0L;
  117.     SetRect(&scrollRect, 0, 0, 509, HEADLINE_BOTTOM);
  118.     SetRect(&scrollSource, 1+gScrollSpeed, 0, 509, HEADLINE_BOTTOM);
  119.     SetRect(&scrollDest, 1, 0, 509-gScrollSpeed, HEADLINE_BOTTOM);
  120.     wholeSource=wholeDest=scrollRect;
  121.     OffsetRect(&wholeDest, gMainRect.left+1, gMainRect.top+(342-HEADLINE_BOTTOM)/2);
  122.     
  123.     scrollCGrafPtr=0L;
  124.     scrollGrafPtr=0L;
  125.     
  126.     if ((theDepth = GetMainScreenDepth()) > 2)
  127.     {
  128.         isColorScroll=TRUE;
  129.         scrollCGrafPtr = &scrollCGrafPort;
  130.         OpenCPort(scrollCGrafPtr);
  131.         
  132.         offRowBytes = (((theDepth * (scrollRect.right - scrollRect.left)) + 15) >> 4) << 1;
  133.         sizeOfOff = (long)(scrollRect.bottom - scrollRect.top) * offRowBytes;
  134.         OffsetRect(&scrollRect, -scrollRect.left, -scrollRect.top);
  135.         
  136.         scrollBits = NewPtr(sizeOfOff);
  137.         if(scrollBits == 0L)
  138.             ErrorString("\pThere is not enough memory.","\p");
  139.         
  140.         (**(scrollCGrafPort).portPixMap).baseAddr = scrollBits;
  141.         (**(scrollCGrafPort).portPixMap).rowBytes = offRowBytes + 0x8000;
  142.         (**(scrollCGrafPort).portPixMap).bounds = scrollRect;
  143.         
  144.         scrollCGrafPort.portRect = scrollRect;
  145.         
  146.         scrollCMHandle = (**(**GetMainDevice()).gdPMap).pmTable;
  147.         err = HandToHand((Handle *)&scrollCMHandle);
  148.         if(err != noErr)
  149.             ErrorString("\pThere is not enough memory.","\p");
  150.         
  151.         for(j = 0; j <= (**scrollCMHandle).ctSize; j++)
  152.             (**scrollCMHandle).ctTable[j].value = j;
  153.         (**scrollCMHandle).ctFlags &= 0x7fff;
  154.         (**scrollCMHandle).ctSeed = GetCTSeed();
  155.         
  156.         (**(scrollCGrafPort).portPixMap).pmTable = scrollCMHandle;
  157.         
  158.         SetPort((GrafPtr)scrollCGrafPtr);
  159.         FillRect(&wholeSource, &qd.black);
  160.     }
  161.     else
  162.     {
  163.         isColorScroll=FALSE;
  164.         scrollGrafPtr = &scrollGrafPort;
  165.         OpenPort(scrollGrafPtr);
  166.         
  167.         offRowBytes = (((scrollRect.right - scrollRect.left) + 15) >> 4) << 1;
  168.         sizeOfOff = (long)(scrollRect.bottom - scrollRect.top) * offRowBytes;
  169.         OffsetRect(&scrollRect, -scrollRect.left, -scrollRect.top);
  170.         
  171.         scrollBits = NewPtr(sizeOfOff);
  172.         if(scrollBits == 0L)
  173.             ErrorString("\pThere is not enough memory.", "\p");
  174.         
  175.         scrollGrafPort.portBits.baseAddr = scrollBits;
  176.         scrollGrafPort.portBits.rowBytes = offRowBytes;
  177.         scrollGrafPort.portBits.bounds = scrollRect;
  178.         scrollGrafPort.portRect = scrollRect;
  179.         
  180.         SetPort(scrollGrafPtr);
  181.         FillRect(&wholeSource, &qd.black);
  182.     }
  183.         
  184.     gTheText=GetResource('Jot2', 1);
  185.     iv=0x42;
  186.     scrollXPos=509;
  187. }
  188.  
  189. void ShutDownScroll(void)
  190. {
  191.     ReleaseResource(gTheText);
  192.  
  193.     if (scrollCGrafPtr!=0L)
  194.     {
  195.         DisposeHandle((Handle)(**(scrollCGrafPort).portPixMap).pmTable);
  196.         DisposePtr((**(scrollCGrafPort).portPixMap).baseAddr);
  197.         CloseCPort(scrollCGrafPtr);
  198.         scrollCGrafPtr=0L;
  199.     }
  200.     if (scrollGrafPtr!=0L)
  201.     {
  202.         DisposePtr(scrollGrafPort.portBits.baseAddr);
  203.         ClosePort(scrollGrafPtr);
  204.         scrollGrafPtr=0L;
  205.     }
  206.     DisposPtr(scrollBits);
  207. }
  208.  
  209. short GetMainScreenDepth(void)
  210. {
  211.     return (gHasColorQD) ? (**(**GetMainDevice()).gdPMap).pixelSize : 1;
  212. }
  213.